//
//  UIViewControllerExtension.swift
//  DragonWallet
//
//  Created by volantPig on 2024/2/21.
//

import UIKit

class UIViewControllerExtension: NSObject {

}

extension UIViewController {
    
    func getCurrentTabBarController() -> UITabBarController? {
        var parent = self.parent
        while parent != nil {
            if let tabBarController = parent as? UITabBarController {
                return tabBarController
            }
            parent = parent?.parent
        }
        return nil
    }
    
    func presentVC(_ viewControllerToPresent: UIViewController, animated flag: Bool = true, completion: (() -> Void)? = nil) {
        viewControllerToPresent.modalPresentationStyle = .fullScreen
        self.present(viewControllerToPresent, animated: flag, completion: completion)
    }
    
    func hidesBottomBarPushViewController(_ viewController: UIViewController, animated: Bool = true) {
        if let navigation = self.navigationController {
            self.hidesBottomBarWhenPushed = true
            navigation.pushViewController(viewController, animated: animated)
            if navigation.viewControllers[0] == self {
                self.hidesBottomBarWhenPushed = false
            }
        }
    }
}
